﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.DirectoryServices;
using Microsoft.EnterpriseManagement;
using Microsoft.EnterpriseManagement.Administration;
using Microsoft.EnterpriseManagement.Common;
using Microsoft.EnterpriseManagement.Configuration;
using Microsoft.EnterpriseManagement.Monitoring;

namespace SilverlightMaintenanceMode.Web.Service
{
    /// <summary>
    /// Summary description for MaintenanceModeService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class MaintenanceModeService : System.Web.Services.WebService
    {

        [WebMethod]
        public List<String> GetRegisteredRootManagementServers()
        {
            List<String> returnValues = new List<String>();
            
            DirectorySearcher searcher = new DirectorySearcher();
            searcher.Filter = "CN=SDKServiceSCP";

            SearchResultCollection resultCollection = searcher.FindAll();
            foreach (SearchResult result in resultCollection)
            {
                returnValues.Add(result.Properties["servicednsname"][0].ToString());
            }
            return returnValues;
        }
    }
}
